<?php

namespace App\Http\Controllers\App;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\ArticleDetail;
use App\Models\ArticleCategory;
use App\Models\ArticleLabel;
use App\Models\ArticleLabelRelation;

class ArticleController extends Controller
{   

    /**
     * 获取文章列表
     *
     * @param Request $request
     * @return void
     */
    public function list(Request $request)
    {
        $cate_id = $request->input('cate_id', 0);
        $type    = $request->input('type', 0);
        $status  = $request->input('status', 0);
        $limit   = $request->input('limit', 20);

        $query = new ArticleDetail;

        if($cate_id){

            $query->where('cate_id', $cate_id);

        }

        if($type){

            $query->where('type', $type);

        }

        if($status){

            $query->where('status', $status);

        }

        $info = $query->orderBy('updated_at', 'desc')->paginate($limit);

        return self::json($info);

    }

    /**
     * 获取文章详情
     *
     * @param Request $request
     * @return void
     */
    public function detail(Request $request)
    {
        $id = $request->input('id', 0);

        $info = ArticleDetail::find($id);

        return self::json($info);
    }

    /**
     * 获取分类列表
     *
     * @param Request $request
     * @return void
     */
    public function cate_list(Request $request)
    {
        $limit   = $request->input('limit', 20);

        $info = ArticleCategory::where('parent_id', 0)->where('status', 1)->orderBy('updated_at', 'desc')->get();

        return self::json($info);
        
    }

}
